using System;
using System.Reflection;
using System.Collections.Generic;

using Newtonsoft.Json;

using ContinualFlame.Ajax;

namespace ContinualFlame.Locus
{	
	public class GameController
	{
		SynchronizedStream _chatStream = new SynchronizedStream("globalChatStream");
		Session _s;
		
		public GameController(Session s)
		{
			_s = s;
			
			_s.SyncManager.RegisterBroadcastSource(_chatStream);
		}
		
		void HandleCenterMap(CenterMap msg)
		{
			
		}
		
		void HandleChatCommand(ChatCommand msg)
		{	
			ChatContent c = new ChatContent();
			c.Content = "<div>woot: " + msg.Command + "</div>\r\n";
			_chatStream.Send(c);
		}
		
		public void Process(string type, string jsonMessage)
		{
			switch (type)
			{
			case "CenterMap":
				HandleCenterMap(
					JsonConvert.DeserializeObject<CenterMap>(jsonMessage));
				break;
			
			case "ChatCommand":
				HandleChatCommand(
					JsonConvert.DeserializeObject<ChatCommand>(jsonMessage));				                 
				break;
				
			case "PingMap":
				break;
			}
		}
	}
}
